//
//  vc1.m
//  DemoProject
//
//  Created by liu xiwang on 2018/4/11.
//  Copyright © 2018年 Sunqk. All rights reserved.
//

#import "vc1.h"

@interface vc1 ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (nonatomic,strong)UIButton  * btnToVC2;
@property (nonatomic,strong)NSMutableArray * arr;
@end

@implementation vc1

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpView];
    NSLog(@"111");
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    
}

#pragma mark   UI
-(void)setUpView{
    self.navigationItem.title = @"首页";
    [self.view addSubview:self.btnToVC2];
    [self.view updateConstraintsIfNeeded];
    __weak typeof(self) weakSelf = self;
    self.tableView.emetyLoad = ^{
        [weakSelf loadData];
    };
}

- (void)updateViewConstraints {
    [super updateViewConstraints];
//    if (self.tableView.translatesAutoresizingMaskIntoConstraints) {
//        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.edges.equalTo(self.view);
//        }];
//    }
    
    [self.btnToVC2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).offset(200);
    }];
}

#pragma mark   getData
- (void)loadData {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        self.arr = [NSMutableArray arrayWithObjects:@"111",@"222",@"333", nil];
        [self setIsLoadedData:YES];
        [self.tableView setLoading:NO];
        [self.tableView setEmetyType:EmetyType_NoNet];
        [self.tableView reloadData];
    });
}

- (void)getLoadDataBase:(NSNotification *)text{
    [super getLoadDataBase:text];
    [self loadData];
}  

#pragma mark   Method
-(void)toOther{
//   [ArbPushUtil runtimePush:@"vc2" dic:@{} nav:self.navigationController];
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil];
}

#pragma mark   UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = self.arr[indexPath.row];
    return cell;
}

#pragma mark   geter/setter
-(UIButton *)btnToVC2{
    if (!_btnToVC2) {
        _btnToVC2 = [[UIButton alloc]init];
        _btnToVC2.backgroundColor = [UIColor redColor];
        [_btnToVC2 addTarget:self action:@selector(toOther) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnToVC2;
}

-(NSMutableArray *)arr{
    if (!_arr) {
        _arr = [NSMutableArray array];
    }
    return _arr;
}
@end
